package com.linkstec.szkettle;

import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.repository.kdr.KettleDatabaseRepository;
import org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta;
/**
 * 创建oracle资源库
 * @author lyl
 *
 */
public class RepositoryCreateTest {
	 public static RepositoryCreateTest transDemo;
	
	/**
	 * 数据库连接信息,适用于DatabaseMeta其中 一个构造器DatabaseMeta(String xml)
	 */
	 public static final String[] databasesXML = {
	        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
	          "<connection>" +
	            "<name>kettle</name>" +
	            "<server>localhost</server>" +
	            "<type>Oracle</type>" +
	            "<access>Native</access>" + 
	            "<database>orcl</database>" +
	            "<port>1521</port>" +
	            "<username>kettle</username>" +
	            "<password>kettle</password>" +
	          "</connection>",
	          "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
	          "<connection>" +
	            "<name>kkkk</name>" +
	            "<server>192.168.10.130</server>" +
	            "<type>Oracle</type>" +
	            "<access>Native</access>" + 
	            "<database>orcl</database>" +
	            "<port>1521</port>" +
	            "<username>kettle</username>" +
	            "<password>kettle</password>" +
	          "</connection>"
	    };	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			KettleEnvironment.init(); 
	        //创建DB资源库 
	        KettleDatabaseRepository repository=new KettleDatabaseRepository(); 
	        DatabaseMeta databaseMeta=new DatabaseMeta("local","Oracle","Native(JDBC)",
	        		"localhost","orcl","1521","kettle","kettle");
	        //选择资源库 
	        KettleDatabaseRepositoryMeta kettleDatabaseRepositoryMeta =
	        		new KettleDatabaseRepositoryMeta("local","kettle","Transformation description",databaseMeta); 
	        repository.init(kettleDatabaseRepositoryMeta);
	        repository.create();
	        // 连接资源库 
	        repository.connect("admin","admin");
	        // 保存进资源库
			
		} catch (Exception e) {
			e.printStackTrace();
			return;
		}
	}
}